﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


namespace MIT.DivAdmin
{
    public partial class DivAdminCalender : System.Web.UI.Page
    {
        String Req1;
        String Req2;
        String Req3;
        String NewsDate1;
        String NewsDate2;
        String NewsDate3;
        String NewsTitle1;
        String NewsTitle2;
        String NewsTitle3;
        String NewsDetails1;
        String NewsDetails2;
        String NewsDetails3;

        int InterviewNo = 0;
        String InterviewDate;
        protected void Page_Load(object sender, EventArgs e)
        {
            String Name = (String)Session["LoggingInfo"];
            String Position = (String)Session["LoggingPosition"];
            String username = (String)Session["LoggingInfoUsername"];
            LabelDivAdminName.Text = Name;
            LabelDivAdminPosition.Text = "(" + Position + ")";

            ImageProfile.ImageUrl = "../ProfilePicHandler.ashx?uname=" + username;

            Session["CalLoggingInfo"] = Name;
            Session["CalLoggingPosition"] = Position;
            Session["CalLoggingInfoUsername"] = username;

            ///////////////////Notification Number//////////////////////////////////////////////////
            string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;

            using (SqlConnection con = new SqlConnection(CS))
            {
                SqlCommand ReqMsgNo = new SqlCommand("spMsgCounter", con);
                ReqMsgNo.CommandType = CommandType.StoredProcedure;

                SqlParameter ReqName3 = new SqlParameter("@username", username);
                ReqMsgNo.Parameters.Add(ReqName3);



                con.Open();
                SqlDataReader dr;

                dr = ReqMsgNo.ExecuteReader();

                if (dr.Read())
                {
                    Req1 = Convert.ToString(dr["REQUEST1"]);
                    Req2 = Convert.ToString(dr["REQUEST2"]);
                    Req3 = Convert.ToString(dr["REQUEST3"]);
                }

            }
            if (Req1 == "")
            {
                LabelMsgNo.Text = "";

            }
            else if (Req2 == "")
            {
                LabelMsgNo.Text = "1";
            }
            else if (Req3 == "")
            {
                LabelMsgNo.Text = "2";
            }
            else
            {
                LabelMsgNo.Text = "3";
            }


            using (SqlConnection con = new SqlConnection(CS))
            {
                SqlCommand GetNews = new SqlCommand("spGetNews1", con);
                GetNews.CommandType = CommandType.StoredProcedure;

                SqlParameter News1 = new SqlParameter("@News1", 1);
                GetNews.Parameters.Add(News1);



                con.Open();
                SqlDataReader dr;

                dr = GetNews.ExecuteReader();

                if (dr.Read())
                {
                    NewsDate1 = Convert.ToString(dr["LiveDate"]);
                    NewsTitle1 = Convert.ToString(dr["Title"]);
                    NewsDetails1 = Convert.ToString(dr["Details"]);

                }

            }

            using (SqlConnection con = new SqlConnection(CS))
            {
                SqlCommand GetNews = new SqlCommand("spGetNews2", con);
                GetNews.CommandType = CommandType.StoredProcedure;

                SqlParameter News2 = new SqlParameter("@News2", 2);
                GetNews.Parameters.Add(News2);



                con.Open();
                SqlDataReader dr;

                dr = GetNews.ExecuteReader();

                if (dr.Read())
                {
                    NewsDate2 = Convert.ToString(dr["LiveDate"]);
                    NewsTitle2 = Convert.ToString(dr["Title"]);
                    NewsDetails2 = Convert.ToString(dr["Details"]);

                }

            }

            using (SqlConnection con = new SqlConnection(CS))
            {
                SqlCommand GetNews = new SqlCommand("spGetNews3", con);
                GetNews.CommandType = CommandType.StoredProcedure;

                SqlParameter News3 = new SqlParameter("@News3", 3);
                GetNews.Parameters.Add(News3);



                con.Open();
                SqlDataReader dr;

                dr = GetNews.ExecuteReader();

                if (dr.Read())
                {
                    NewsDate3 = Convert.ToString(dr["LiveDate"]);
                    NewsTitle3 = Convert.ToString(dr["Title"]);
                    NewsDetails3 = Convert.ToString(dr["Details"]);
                }

            }



            LabelDetails1.Text = NewsDetails1;
            LabelDetails2.Text = NewsDetails2;
            LabelDetails3.Text = NewsDetails3;

            LabelNews1.Text = NewsTitle1;
            LabelNews2.Text = NewsTitle2;
            LabelNews3.Text = NewsTitle3;

            LabelDate1.Text = NewsDate1;
            LabelDate2.Text = NewsDate2;
            LabelDate3.Text = NewsDate3;


            if (!IsPostBack)
            {
                Calendar1.Visible = false;
            }
        }



     
        protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
        {
            if (e.Day.IsSelected)
            {
                e.Day.IsSelectable = false;
                e.Cell.BackColor = System.Drawing.Color.OrangeRed;
            }

            if (e.Day.IsOtherMonth || e.Day.IsWeekend)
            {
                e.Day.IsSelectable = false;
                e.Cell.BackColor = System.Drawing.Color.Maroon;
            }

            if (e.Day.Date.CompareTo(DateTime.Today) < 0)
            {
                e.Day.IsSelectable = false;
                e.Cell.BackColor = System.Drawing.Color.GhostWhite;
            }

        }

        protected void ImageButton1_Click1(object sender, ImageClickEventArgs e)
        {
            Calendar1.Visible = true;

            //String InterviewDate = Calendar1.SelectedDate.ToString();
        }

        protected void ButtonLogout_Click(object sender, EventArgs e)
        {
            Response.Redirect("../Login/SignIn.aspx");
        }

        protected void Button1_Click(object sender, EventArgs e)
        {

            if (DropDownListMode.SelectedValue == "First Interview")
            {
                string CS = ConfigurationManager.ConnectionStrings["DBCSFINAL"].ConnectionString;
                using (SqlConnection con = new SqlConnection(CS))
                {
                    SqlCommand cmd = new SqlCommand("spAddInterview1", con);


                    cmd.CommandType = System.Data.CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@INTERVIEWMODE", DropDownListMode.SelectedValue);
                    cmd.Parameters.AddWithValue("@INTERVIEWDATE", TextBoxDate.Text);
                    cmd.Parameters.AddWithValue("@ROOM_CODE", DropDownListVenue.SelectedValue);
                    cmd.Parameters.AddWithValue("@I_STARTS", DropDownListFrom.SelectedValue);
                    cmd.Parameters.AddWithValue("@I_ENDS", DropDownListTo.SelectedValue);

                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();

                    SqlCommand com3 = new SqlCommand("spGetInterviewNo", con);
                    com3.CommandType = CommandType.StoredProcedure;

                    SqlParameter sendname5 = new SqlParameter("@INTERVIEWMODE", DropDownListMode.SelectedValue);
                    com3.Parameters.Add(sendname5);
                    SqlParameter sendname1 = new SqlParameter("@INTERVIEWDATE", TextBoxDate.Text);
                    com3.Parameters.Add(sendname1);
                    SqlParameter sendname2 = new SqlParameter("@ROOM_CODE", DropDownListVenue.SelectedValue);
                    com3.Parameters.Add(sendname2);
                    SqlParameter sendname3 = new SqlParameter("@I_STARTS", DropDownListFrom.SelectedValue);
                    com3.Parameters.Add(sendname3);
                    SqlParameter sendname4 = new SqlParameter("@I_ENDS", DropDownListTo.SelectedValue);
                    com3.Parameters.Add(sendname4);



                    con.Open();
                    SqlDataReader dr2;

                    dr2 = com3.ExecuteReader();

                    if (dr2.Read())
                    {
                        InterviewNo = Convert.ToInt32(dr2["INTERVIEW_NO"]);


                    }
                    InterviewDate = TextBoxDate.Text;
                    Session["InterviewNo"] = InterviewNo;
                    Session["InterviewDate"] = InterviewDate;
                    Session["BoardRoom"] = DropDownListVenue.SelectedValue;
                    Session["Mode"] = DropDownListMode.SelectedValue;

                    Response.Redirect("DivAdminCalender2.aspx");
                 }

            
            }

            else if (DropDownListMode.SelectedValue == "Second Interview")
            {
                string CS = ConfigurationManager.ConnectionStrings["DBCSFINAL"].ConnectionString;
                using (SqlConnection con = new SqlConnection(CS))
                {
                    SqlCommand cmd = new SqlCommand("spAddInterview11", con);


                    cmd.CommandType = System.Data.CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@INTERVIEWMODE", DropDownListMode.SelectedValue);
                    cmd.Parameters.AddWithValue("@INTERVIEWDATE", TextBoxDate.Text);
                    cmd.Parameters.AddWithValue("@ROOM_CODE", DropDownListVenue.SelectedValue);
                    cmd.Parameters.AddWithValue("@I_STARTS", DropDownListFrom.SelectedValue);
                    cmd.Parameters.AddWithValue("@I_ENDS", DropDownListTo.SelectedValue);

                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();

                    SqlCommand com3 = new SqlCommand("spGetInterviewNoTwo", con);
                    com3.CommandType = CommandType.StoredProcedure;

                    SqlParameter sendname5 = new SqlParameter("@INTERVIEWMODE", DropDownListMode.SelectedValue);
                    com3.Parameters.Add(sendname5);
                    SqlParameter sendname1 = new SqlParameter("@INTERVIEWDATE", TextBoxDate.Text);
                    com3.Parameters.Add(sendname1);
                    SqlParameter sendname2 = new SqlParameter("@ROOM_CODE", DropDownListVenue.SelectedValue);
                    com3.Parameters.Add(sendname2);
                    SqlParameter sendname3 = new SqlParameter("@I_STARTS", DropDownListFrom.SelectedValue);
                    com3.Parameters.Add(sendname3);
                    SqlParameter sendname4 = new SqlParameter("@I_ENDS", DropDownListTo.SelectedValue);
                    com3.Parameters.Add(sendname4);



                    con.Open();
                    SqlDataReader dr2;

                    dr2 = com3.ExecuteReader();

                    if (dr2.Read())
                    {
                        InterviewNo = Convert.ToInt32(dr2["INTERVIEW_NO"]);


                    }
                    InterviewDate = TextBoxDate.Text;
                    Session["InterviewNo"] = InterviewNo;
                    Session["InterviewDate"] = InterviewDate;
                    Session["BoardRoom"] = DropDownListVenue.SelectedValue;
                    Session["Mode"] = DropDownListMode.SelectedValue;

                    Response.Redirect("DivAdminCalender2.aspx");
                }


            }

            else if (DropDownListMode.SelectedValue == "Final Interview")
            {
                string CS = ConfigurationManager.ConnectionStrings["DBCSFINAL"].ConnectionString;
                using (SqlConnection con = new SqlConnection(CS))
                {
                    SqlCommand cmd = new SqlCommand("spAddInterview111", con);


                    cmd.CommandType = System.Data.CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@INTERVIEWMODE", DropDownListMode.SelectedValue);
                    cmd.Parameters.AddWithValue("@INTERVIEWDATE", TextBoxDate.Text);
                    cmd.Parameters.AddWithValue("@ROOM_CODE", DropDownListVenue.SelectedValue);
                    cmd.Parameters.AddWithValue("@I_STARTS", DropDownListFrom.SelectedValue);
                    cmd.Parameters.AddWithValue("@I_ENDS", DropDownListTo.SelectedValue);

                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();

                    SqlCommand com3 = new SqlCommand("spGetInterviewNoThree", con);
                    com3.CommandType = CommandType.StoredProcedure;

                    SqlParameter sendname5 = new SqlParameter("@INTERVIEWMODE", DropDownListMode.SelectedValue);
                    com3.Parameters.Add(sendname5);
                    SqlParameter sendname1 = new SqlParameter("@INTERVIEWDATE", TextBoxDate.Text);
                    com3.Parameters.Add(sendname1);
                    SqlParameter sendname2 = new SqlParameter("@ROOM_CODE", DropDownListVenue.SelectedValue);
                    com3.Parameters.Add(sendname2);
                    SqlParameter sendname3 = new SqlParameter("@I_STARTS", DropDownListFrom.SelectedValue);
                    com3.Parameters.Add(sendname3);
                    SqlParameter sendname4 = new SqlParameter("@I_ENDS", DropDownListTo.SelectedValue);
                    com3.Parameters.Add(sendname4);



                    con.Open();
                    SqlDataReader dr2;

                    dr2 = com3.ExecuteReader();

                    if (dr2.Read())
                    {
                        InterviewNo = Convert.ToInt32(dr2["INTERVIEW_NO"]);


                    }
                    InterviewDate = TextBoxDate.Text;
                    Session["InterviewNo"] = InterviewNo;
                    Session["InterviewDate"] = InterviewDate;
                    Session["BoardRoom"] = DropDownListVenue.SelectedValue;
                    Session["Mode"] = DropDownListMode.SelectedValue;

                    Response.Redirect("DivAdminCalender2.aspx");
                }
            }


        }

        protected void Calendar1_SelectionChanged1(object sender, EventArgs e)
        {
            TextBoxDate.Text = Calendar1.SelectedDate.ToShortDateString().ToString();
            Calendar1.Visible = false;
        }

      


    }
}